home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / migd / migd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-10  |  7.6 KB  |  253 lines

  1. /*
  2.  * migd.h --
  3.  *
  4.  *    Declarations of constants and structures used by the migration
  5.  *    daemon.
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /sprite/src/daemons/migd/RCS/migd.h,v 2.2 90/09/24 14:45:38 douglis Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _MIGD
  20. #define _MIGD
  21.  
  22. #include <sprite.h>
  23. #include <fs.h>
  24. #include <mig.h>
  25. #include <list.h>
  26. #include <pdev.h>
  27.  
  28.  
  29. /*
  30.  * Types of pdev connections:
  31.  *
  32.  *    MIGD_DAEMON    - a daemon is talking to us.
  33.  *    MIGD_USER    - a user process is talking to us.
  34.  *    MIGD_LOCAL    - a local process is talking to us (to get the load
  35.  *              average or perform an eviction).
  36.  *    MIGD_NEW    - the connection is new and we don't know who is at the
  37.  *              other end.
  38.  *    MIGD_CLOSED    - the connection has been forcibly closed and there's
  39.  *              nothing more we need to do with it.
  40.  */
  41. typedef enum {
  42.     MIGD_DAEMON,
  43.     MIGD_USER,
  44.     MIGD_LOCAL,
  45.     MIGD_NEW,
  46.     MIGD_CLOSED,
  47. } Migd_ServiceType;
  48.  
  49. /*
  50.  * Define a structure to keep track of open connections.
  51.  * This is reachable from the ClientData part of a Pdev_Stream.
  52.  */
  53. typedef struct {
  54.     List_Links nextStream;    /* Next stream we have open. */
  55.     Pdev_Stream *streamPtr;    /* Back pointer to pdev info. */
  56.     Migd_ServiceType type;    /* Type of connection. */
  57.     int user;            /* User invoked by. */
  58.     int host;            /* Host invoked by. */
  59.     int processID;        /* Process ID of invoker. */
  60.     int openID;                /* Unique identifier. */
  61.     int    defaultSelBits;        /* What to set default to after an
  62.                    operation. */
  63.     int format;            /* Byte order of this host (set on first
  64.                    ioctl, used by read/write). */
  65.     int    numRequested;        /* Total number of hosts requested. */
  66.     int numObtained;        /* Total number of hosts obtained. */
  67.     int numEvicted;        /* Total number of hosts given and then
  68.                    reclaimed due to eviction. */
  69.     int numInUse;        /* Number of hosts currently assigned to this
  70.                    process, which is the length of the
  71.                    currentRequests list. */
  72.     int    maxRequests;        /* Maximum number of hosts requested.
  73.                    This may be less than numRequested if
  74.                    hosts are assigned, then returned (or
  75.                    reclaimed), then assigned again. */
  76.     int    maxObtained;        /* Maximum number of hosts obtained.
  77.                    This may be less than numAssigned if
  78.                    hosts are assigned, then returned (or
  79.                    reclaimed), then assigned again. */
  80.     int denied;            /* Non-zero if ever denied a host request. */
  81.     int    numStolen;        /* Number of times we stole hosts back. */
  82.     int    stoleTime;        /* Time at which we stole hosts back. */
  83.     List_Links currentRequests;    /* List of outstanding requests. */
  84.     List_Links messages;    /* Messages to pass to process, defined in
  85.                    global.c. */
  86.     struct Migd_WaitList *waitPtr; /* Waiting list, if any. */
  87. } Migd_OpenStreamInfo;
  88.  
  89. /* 
  90.  * Define a structure for keeping track of clients that want more
  91.  * hosts than we can give them.
  92.  */
  93. typedef struct Migd_WaitList {
  94.     List_Links links;        /* Link to next client. */
  95.     Migd_OpenStreamInfo *cltPtr;/* Client. */
  96. } Migd_WaitList;
  97.  
  98. /*
  99.  * Define a structure for managing host information.  This is
  100.  * a superset of the Mig_Info that clients can see.
  101.  */
  102. typedef struct Migd_Info {
  103.     List_Links    links;        /* Links within list of idle hosts. */
  104.     Mig_Info    info;        /* Standard info. */
  105.     int        archType;    /* Numeric identifier for architecture type. */
  106.     int     flags;        /* Additional info, defined below. */
  107.     List_Links  clientList;    /* Clients using this host
  108.                    (Migd_RequestInfo structures). */
  109.     Migd_OpenStreamInfo *cltPtr; /* Pointer back to open stream info
  110.                        for daemon. */
  111.     char     *name;        /* Name of host, for debugging purposes. */
  112.     int        lastHostAssigned; /* Host running process to which this host
  113.                      was last assigned. Used for
  114.                      statistical purposes. */
  115. } Migd_Info;
  116.  
  117. /*
  118.  * Flags for Migd_Info:
  119.  *    MIGD_CHECK_COUNT    - Check when the count of foreign
  120.  *                  processes decreases to determine when
  121.  *                  host is idle again.
  122.  *    MIGD_WAS_EMPTY        - Host had no foreign processes the
  123.  *                  last time we checkpointed.
  124.  */
  125. #define MIGD_CHECK_COUNT 1    
  126. #define MIGD_WAS_EMPTY   2    
  127.  
  128. /*
  129.  * Subscripts into the queueThreshold array.
  130.  */
  131. #define MIGD_MIN_THRESHOLD 0
  132. #define MIGD_MAX_THRESHOLD 1
  133.  
  134. /*
  135.  * Arbitrary value larger than the load average on any node (we hope!)
  136.  */
  137. #define MIGD_MAX_LOAD 1000.0
  138.  
  139. /*
  140.  * If we have to deal with severe clock skew, define USE_GLOBAL_CLOCK.
  141.  */
  142. #define USE_GLOBAL_CLOCK
  143.  
  144.  
  145. #define mnew(type)    (type *)Malloc(sizeof(type))
  146.  
  147. /*
  148.  * We always want to print our processID because we want to catch multiple
  149.  * daemons using the same log file.
  150.  */
  151. #define PRINT_PID fprintf(stderr, "%x: ", migd_Pid)
  152.  
  153. /*
  154.  * We probably always want to log certain messages to syslog, but we
  155.  * also want them to go to a log file -- at least while syslog isn't
  156.  * logged permanently!
  157.  */
  158. #define SYSLOG0(level, message) \
  159.     syslog(level, message); \
  160.     if (migd_LogToFiles) { \
  161.     PRINT_PID; \
  162.     fprintf(stderr, message); \
  163.     }
  164. #define SYSLOG1(level, message, arg1) \
  165.     syslog(level, message, arg1); \
  166.     if (migd_LogToFiles) { \
  167.     PRINT_PID; \
  168.     fprintf(stderr, message, arg1); \
  169.     }
  170. #define SYSLOG2(level, message, arg1, arg2) \
  171.     syslog(level, message, arg1, arg2); \
  172.     if (migd_LogToFiles) { \
  173.     PRINT_PID; \
  174.     fprintf(stderr, message, arg1, arg2); \
  175.     }
  176. #define SYSLOG3(level, message, arg1, arg2, arg3) \
  177.     syslog(level, message, arg1, arg2, arg3); \
  178.     if (migd_LogToFiles) { \
  179.     PRINT_PID; \
  180.     fprintf(stderr, message, arg1, arg2, arg3); \
  181.     }
  182. #define DATE() \
  183.     if (migd_LogToFiles) { \
  184.         int t; \
  185.     t = time(0); \
  186.     fprintf(stderr, "%x %s", migd_Pid, ctime(&t)); \
  187.     }
  188.  
  189. /*
  190.  * Macro to add to a counter, watching for overflow.  We use unsigned
  191.  * integers and wrap around if the high-order bit gets set.  This assumes
  192.  * that the amount to be added each time is
  193.  * relatively small (so we can't miss the overflow bit).
  194.  */
  195.  
  196. #define OVERFLOW_BIT (1 << (sizeof(unsigned int) * 8 - 1))
  197. #define ADD_WITH_OVERFLOW(counter, thisCount) \
  198.     counter[MIG_COUNTER_LOW] += thisCount; \
  199.     if (counter[MIG_COUNTER_LOW] & OVERFLOW_BIT) { \
  200.         counter[MIG_COUNTER_HIGH] += 1; \
  201.         counter[MIG_COUNTER_LOW] &= ~OVERFLOW_BIT; \
  202.     }
  203.  
  204.  
  205.  
  206.  
  207.  
  208. extern char     *Malloc();        /* Utility. */
  209.  
  210. extern int    migd_Debug;
  211. extern int    migd_Quit;
  212. extern int    migd_Verbose;
  213. extern int    migd_DontFork;
  214. extern int    migd_Version;
  215. extern int    migd_DoStats;
  216. extern int    migd_NeverEvict;
  217. extern int    migd_NeverRunGlobal;
  218. extern int    migd_LogToFiles;
  219. extern int    migd_AlwaysAccept;
  220. extern int    migd_GlobalMaster;
  221. extern int    migd_Pid;
  222. extern char    *migd_GlobalPdevName;
  223. extern char    *migd_GlobalErrorName;    /* Place to write errors for global
  224.                        daemon, or NULL. */
  225. extern char    *migd_LocalPdevName;
  226. extern char    *migd_ProgName;
  227. extern int    migd_HostID;
  228. extern char    *migd_HostName;
  229. extern int    migd_AlwaysAccept;
  230. extern int    migd_NeverAccept;
  231. extern int    migd_MigVersion;
  232. extern int    migd_WriteInterval;
  233. extern int    migd_LoadInterval;
  234. extern double    migd_Weights[];
  235. extern Mig_SystemParms migd_Parms;
  236. extern Fs_TimeoutHandler migd_TimeoutToken;
  237.  
  238. extern void    Migd_GatherLoad();
  239. extern void    Migd_GetLocalLoad();
  240. extern void    Migd_End();
  241. extern int    Migd_CreateGlobal();
  242. extern int    Migd_ContactGlobal();
  243. extern void     Migd_HandleRequests();
  244. extern void     Migd_Evict();
  245. extern int    Migd_GetParms();
  246. extern int    Migd_SetParms();
  247. extern int    Migd_EvictIoctl();
  248.  
  249. #endif _MIGD
  250.  
  251.  
  252.  
  253.